<?php 
 
    session_start();
    include_once "conexion.php";
 
    function verificar_login($user,$password,&$result)
    {
        $sql = "SELECT * FROM usuarios WHERE usuario = '$user' and password = md5('$password')";
        $rec = mysql_query($sql);
        $count = 0;
        while($row = mysql_fetch_object($rec))
        {
            $count++;
            $result = $row;
        }
        if($count == 1)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    if(!isset($_SESSION['userid']))
    {
        if(isset($_POST['login']))
        {
            if(verificar_login($_POST['user'],$_POST['password'],$result) == 1)
            {
                $_SESSION['userid'] = $result->idusuario;
                $_SESSION['username'] = $result->usuario;
                $_SESSION['name'] = $result->nombres;
                $_SESSION['type'] = $result->type;
                    header("location:index.php");
            }
            else
            {
                echo 'Su usuario es incorrecto, intente nuevamente.';
            }
        }
 
        ?>
<style type="text/css">
<!--
.Estilo3 {	color: #FFFFFF;
	font-family: "Courier New", Courier, monospace;
	font-size: xx-large;
}
.Estilo4 {	color: #CCCCCC;
	font-size: xx-large;
}
.Estilo7 {font-size: large}
-->
</style>

<form action="" method="post">
              <div align="center">
                <table width="656" height="103" border="1">
                  <tr bgcolor="#000000">
                    <th width="551" scope="col"><span class="Estilo3">BIBLIOTECA</span></th>
                  </tr>
                  <tr bgcolor="#0033CC">
                    <th scope="row"><div align="center"><span class="Estilo4"><img src="icno.png" alt="im" width="123" height="163" /><span class="Estilo7">INICIO LIBROS USUARIOS REPORTES ACERCA DE.. </span></span></div></th>
                  </tr>
                  <tr bgcolor="#CCCCCC">
                    <th bgcolor="#FFFFFF" scope="row"><div align="left"></div></th>
                  </tr>
                  <tr bgcolor="#CCCCCC">
                    <th bgcolor="#FFFFFF" scope="row"><span class="Estilo7">BIENVENIDO</span></th>
                  </tr>
                  <tr bgcolor="#CCCCCC">
                    <th bgcolor="#FFFFFF" scope="row"><img src="iconos2.jpg" alt="foto" width="1052" height="283" /></th>
                  </tr>
                  <tr bgcolor="#CCCCCC">
                    <th bgcolor="#FFFFFF" scope="row"><p>Username
                        <input name="user" type="text" class="textbox1" value="" />
                        <br/>
Password
<input name="password" type="password" class="textbox1" />
<br/>
<input name="login" type="submit" value="login" />
</p>
                        <p>
                          <?
    }
    else
    {
        //echo 'INGRESE AL SISTEMA.';
        echo '<a href="logout.php">Logout</a><script>window.location="logout.php";</script>';
    }
?>
</p>
                      <p>&nbsp;</p>
                      <p>&nbsp;</p>
                      <p>&nbsp;</p></th>
                  </tr>
                </table>
  </div>
  </form>
        